package com.example.servlet;

import java.io.*;
import java.util.Optional;
import java.util.UUID;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
    private String message;

    public void init() {
        message = "Hello World!";
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        System.out.println(config);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");

        //Cookie cookie =new Cookie("jssession", UUID.randomUUID().toString());
        //response.addCookie(cookie);
        request.getSession();

        //Thread thread = new Thread();

        ThreadLocal<String> threadLocal = new ThreadLocal<>();
        threadLocal.get();
        threadLocal.set("");
        threadLocal.remove();

        System.out.println("HelloServlet执行");

        // Hello
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h1>" + message + "</h1>");
        out.println("</body></html>");
    }

    public void destroy() {
    }
}